import store from "./store";

const defaultState={
    inputValue:'',
    list:[]
}

export default (state=defaultState,action)=>{
  if(action.type==='change_input_value'){
    //   console.log(state.action)

    //  return{ 
    //         ...state.inputValue,
    //       inputValue: action.value
      
    // }
    const newState=JSON.parse(JSON.stringify(state));
    newState.inputValue=action.value;
    return newState
  }
   if(action.type==='chang_list'){

    //    return{
    //        ...state.list,
           
    //        list: state.list.push(store.inputValue)
    //    }
       
    const newState=JSON.parse(JSON.stringify(state));
    console.log(newState)
    newState.list.push(newState.inputValue);
    newState.inputValue='';
    return newState
   }
   if(action.type==='delete_item'){
    const newState=JSON.parse(JSON.stringify(state));
    newState.list.splice(action.index,1)
    return newState


   }

    return state
}